

*Settings
clear all
cap log close
*Change this to your system name
local user "awcassidy1"
set more off, permanently
cd "C:\Users\awcassidy1\Dropbox\jmp_new\cleaned_data"


use "C:\Users\awcassidy1\Dropbox\jmp_new\cleaned_data/data_with_observability_indices.dta", clear




********************************************************************************
*Baseline: observability groups
********************************************************************************
*standard values
local clustvar "mlsid"
local clustvarword "Home"
local fevars "i.saleyear i.lsaleyear i.yearbuiltcat"
local fe_to_absorb="saleyear lsaleyear yearbuiltcat"
local controls "yearbuiltaudit conditionedsqft"
local baselinevars "parsimonious_less parsimonious_more_fuel parsimonious_more_other"
local filename "main"
local depvar "pricediff"
local not_extracted="duct_type  rsavg  eeravg  sizeavg    negsysageavg ah_type notwinrec  notraddr"
*sample criterion is a full if statement

local parsimonious_less_vars "negleakavg atticrvalue ductravg     "
local parsimonious_more_vars_fuel "fftype whftype "
local parsimonious_more_vars_other "ah_location progtherm twosystems"


********************************************************************************
*VAR DEFINITIONS AND LABELS
********************************************************************************
gen pre_above_med_ee=above_median_ee_all_mean*pre
gen post_above_med_ee= above_median_ee_all_mean*post
la var pre_above_med_ee "Above Med EE $\times$ Pre-sample"
la var post_above_med_ee "Above Med EE $\times$ Post"
la var above_median_ee_all_mean "Above Med EE"
la var above_median_less "Above Med Less"

gen pre_above_med_less=above_median_less*pre
gen post_above_med_less= above_median_less*post
la var pre_above_med_less "Above Med Less $\times$ Pre-sample"
la var post_above_med_less "Above Med Less $\times$ Post"

**# Bookmark #1
gen pre_Less_st = Less_st*pre
gen post_Less_st = Less_st*post
la var pre_Less_st "Less $\times$ Pre"
la var post_Less_st "Less $\times$ Post"

gen pre_More_Fuel_st = More_Fuel_st*pre
gen post_More_Fuel_st = More_Fuel_st*post
la var pre_More_Fuel_st "More-Fuel $\times$ Pre"
la var post_More_Fuel_st "More-Fuel $\times$ Post"

gen pre_More_Other_st = More_Other_st*pre
gen post_More_Other_st = More_Other_st*post
la var pre_More_Other_st "More-Other $\times$ Pre"
la var post_More_Other_st "More-Other $\times$ Post"	

	
	


********************************************************************************
*Heterogeneity by Square Footage and Home Age
********************************************************************************
*make a local that will contain extra variables for this regression
capture drop age_* sqft_*
gen age_sale_2 = saleyear-year_built
la var age_sale_2 "Age at Sale 2"


local baselinevars "Less_st More_Fuel_st More_Other_st"
local baselinevars_st "Less_st More_Fuel_st More_Other_st"
local sqftvars=""
local sqftvars_st=""
local agevars=""
local agevars_st=""

*put sqft in thousands
replace conditionedsqft=conditionedsqft/1000

*use demeaned sqft and age
sum conditionedsqft
replace conditionedsqft=conditionedsqft-r(mean)

sum age_sale_2
replace age_sale_2=age_sale_2-r(mean)



foreach v in `baselinevars' {
	gen sqft_`v'=conditionedsqft*`v'
	*gen sqft_`v'_st=sqfttotal*`v'_st
	gen age_`v'=age_sale_2*`v'
	*gen age_`v'_st=age_sale_2*`v'_st
	local sqftvars="`sqftvars' sqft_`v'"
	*local sqftvars_st "`sqftvars_st' sqft_`v'_st"
	*local agevars_st="`agevars_st' age_`v'_st"
	local agevars="`agevars' age_`v'"
	la var age_`v' "Age $ \times $ `: var label `v''"
	la var sqft_`v' "Sqft $ \times $ `: var label `v''"
	}
	
di `hetvars'

eststo clear

*sqft
eststo: xi: reghdfe pricediff `sqftvars' `baselinevars' conditionedsqft  ///
	 , vce(cl mlsid) absorb(saleyear lsaleyear yearbuiltcat)
	
estadd scalar r2all = e(r2)

test `sqftvars'

estadd scalar jointpsqft =r(p)

estadd local stdzd="\multicolumn{1}{c}{No}"


*unstandardized age
eststo: xi: reg pricediff `agevars' `baselinevars' age_sale_2  ///
	i.saleyear i.lsaleyear , vce(cl mlsid)
	
estadd scalar r2all = e(r2)


estadd local stdzd="\multicolumn{1}{c}{No}"

test `agevars'

estadd scalar jointpage =r(p)

********************************************************************************
*LESS ONLY
********************************************************************************
eststo clear

*less only

eststo: xi: reg pricediff age_Less_st Less_st age_sale_2  ///
	i.saleyear i.lsaleyear i.yearbuiltcat, vce(cl mlsid)
	

estadd local stdzd="\multicolumn{1}{c}{Yes}"
estadd scalar r2all = e(r2)

eststo: xi: reg pricediff sqft_Less_st Less_st conditionedsqft  ///
	i.saleyear i.lsaleyear i.yearbuiltcat, vce(cl mlsid)
	

estadd local stdzd="\multicolumn{1}{c}{Yes}"
estadd scalar r2all = e(r2)

local keepvars Less_st age_Less_st age_sale_2 sqft_Less_st conditionedsqft 

esttab using "C:\Users\awcassidy1\Dropbox\jmp_new/tables/less_het.tex", replace fragment ///
		keep(`keepvars') order(`keepvars') ///
		 label booktabs nomtitles noobs se(4) b(4) ///
		scalars( ///
				"r2all R-squared" ///
				 "N Observations"  ///
				) ///
				sfmt( %9.3fc %9.0fc %9.0fc) star(* 0.10 ** 0.05 *** 0.01)

